from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import User, PasswordResetCode


@admin.register(User)
class UserAdmin(BaseUserAdmin):
    list_display = ['username', 'email', 'nickname', 'user_type', 'phone', 'created_at']
    list_filter = ['user_type', 'is_active', 'created_at']
    search_fields = ['username', 'email', 'nickname', 'phone']
    
    fieldsets = BaseUserAdmin.fieldsets + (
        ('扩展信息', {
            'fields': ('user_type', 'phone', 'avatar', 'nickname', 'signature', 'interests')
        }),
        ('隐私设置', {
            'fields': ('show_phone', 'show_email', 'show_activities')
        }),
    )


@admin.register(PasswordResetCode)
class PasswordResetCodeAdmin(admin.ModelAdmin):
    list_display = ['user', 'code', 'email', 'phone', 'is_used', 'created_at', 'expires_at']
    list_filter = ['is_used', 'created_at']
    search_fields = ['user__username', 'email', 'phone']
